<template>
  <div>
    <el-dialog
      :title="title"
      :visible="dialogVisible"
      :show-close="false"
      width="750px"
    >
      <el-form
        ref="customerManageDialog"
        :model="row"
        label-width="125px"
        style="margin-left: 10px;"
      >
        <div>
          <div class="container">客户信息</div>
          <el-row>
            <el-col :span="11">
              <el-form-item label="客户姓名:" prop="name">
                <el-input
                  v-model="row.name"
                  size="medium"
                  placeholder="请输入客户姓名"
                />
              </el-form-item>
            </el-col>
            <el-col :span="13">
              <el-form-item label="性别:" prop="sex">
                <el-select v-model="row.sex" placeholder="请选择性别">
                  <el-option value="1" label="男" />
                  <el-option value="0" label="女" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item label="身份证号码:" prop="idcard">
                <el-input
                  v-model="row.idcard"
                  size="medium"
                  placeholder="请输入身份证号码"
                />
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="电话号码:" prop="tel">
                <el-input
                  v-model="row.tel"
                  size="medium"
                  placeholder="请输入电话号码"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div>
          <div class="card-container">身份证照片</div>
          <el-row>
            <el-col :span="12">
              <el-form-item label="身份证正面照片：" prop="img">
                <upload-idcard
                  :folder="folder"
                  :row="row"
                  @upload-success="handleUploadpimg"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证反面照片：" prop="img">
                <upload-n-idcard
                  :folder="folder"
                  :row="row"
                  @upload-success="handleUploadnimg"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div>
          <div class="card-container">驾驶证照片</div>
          <el-row>
            <el-col>
              <el-form-item label="驾驶证照片：" prop="img">
                <upload-drive-img
                  :folder="drivefolder"
                  :row="row"
                  @upload-success="handleUploadDrive"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <span slot="footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="handleConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import UploadDriveImg from '@/components/UploadDriveImg'
import UploadIdcard from '@/components/UploadIdcard'
import UploadNIdcard from '@/components/UploadNIdcard'
export default {
  name: 'CustomerManageDialog',
  components: {
    UploadDriveImg,
    UploadIdcard,
    UploadNIdcard
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      title: '',
      folder: 'idcard',
      drivefolder: 'drive'
    }
  },
  updated() {
    if (this.row.id) {
      this.title = '编辑信息'
    } else {
      this.title = '新增客户'
    }
  },
  methods: {
    handleCancel() {
      this.$emit('cancel-dialog')
      this.$refs.customerManageDialog.resetFields()
    },
    handleConfirm() {
      this.$refs.customerManageDialog.validate((valid) => {
        if (valid) {
          this.$emit('confirm-dialog', {
            id: this.row.id,
            name: this.row.name,
            sex: this.row.sex,
            idcard: this.row.idcard,
            tel: this.row.tel,
            pcardimg: this.row.pcardimg,
            ncardimg: this.row.ncardimg,
            driveimg: this.row.driveimg
          })
        } else {
          return false
        }
      })
    },
    handleUploadDrive(url) {
      this.row.driveimg = url
    },
    handleUploadpimg(url) {
      this.row.pcardimg = url
    },
    handleUploadnimg(url) {
      this.row.ncardimg = url
    }
  }
}
</script>

<style>
  .container {
    margin-left: 30px;
    margin-bottom: 30px;
    font-size: 18px;
  }
  .card-container {
    margin-left: 30px;
    margin-bottom: 30px;
    margin-top: 25px;
    font-size: 18px;
  }
</style>
